package cn.nawang.ebeim.client.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import cn.nawang.ebeim.client.version.VersionTree;

public class KryoSerializer implements VersionTreeSerializer {
  private Kryo kryo = new Kryo();

  @Override
  public void writeObject(String path, VersionTree vt) throws FileNotFoundException, IOException {
    Output output = new Output(new FileOutputStream(path));
    kryo.writeObject(output, vt);
    output.close();
  }

  @Override
  public VersionTree readObject(String path)
      throws FileNotFoundException, IOException, ClassNotFoundException {
    Input input = new Input(new FileInputStream(path));
    VersionTree vt = kryo.readObject(input, VersionTree.class);
    input.close();
    return vt;
  }

}
